﻿using DevComponents.DotNetBar.SuperGrid;
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Zlsy.Core.Data;
using Zlsy.Core.ZlhisModule;

namespace Evision.Zlhis.FeeType.Personnel.Maintenance {
    public partial class 费别人员维护 : BaseForm {
        public string Id { get; set; }
        public int SysId { get; set; }
        public int ModuleId { get; set; }
        public string No { get; set; }
        public string ApprovalType { get; set; }
        DataTable dt = new DataTable();
        ApprovelControlData data = new ApprovelControlData();
        public 费别人员维护() {
            InitializeComponent();
        }

        private void FrmApprovalControl_Load(object sender, EventArgs e) {
            this.WindowState = FormWindowState.Maximized;
            string priv = ClsComLib.GetPrivFunc(SysId, ModuleId);
            btn_add.Visible = priv.Contains("增加");
            btn_exit.Visible = priv.Contains("修改");
            btn_delete.Visible = priv.Contains("删除");
            btn_refresh.Visible = priv.Contains("更新");
            selectValid();
            dgv.ReadOnly = true;
            dgv.Columns["管控ID"].Visible = false;
        }

        private void btn_add_Click(object sender, EventArgs e) {
            Form 特殊费别审批管控编辑 = Application.OpenForms["特殊费别审批管控编辑"];  //查找是否打开过窗体  
            if ((特殊费别审批管控编辑 == null) || (特殊费别审批管控编辑.IsDisposed)) {
                using (费别人员维护编辑 frm = new 费别人员维护编辑()) {
                    if (frm.ShowDialog() == DialogResult.OK) {
                        selectValid();
                    } else {
                        return;
                    }
                }
            } else {
                特殊费别审批管控编辑.Close();
            }
        }

        private void btn_edit_Click(object sender, EventArgs e) {
            DataGridViewSelectedRowCollection selectedRows = dgv.SelectedRows;//选中行
            if (selectedRows == null || selectedRows.Count == 0) {
                MessageBox.Show("请选中一条维护信息");
                return;
            }
            this.Id = Convert.ToString(selectedRows[0].Cells["管控ID"].Value);
            if (!string.IsNullOrEmpty(Id)) {
                Form 特殊费别审批管控编辑 = Application.OpenForms["特殊费别审批管控编辑"];  //查找是否打开过窗体  
                if ((特殊费别审批管控编辑 == null) || (特殊费别审批管控编辑.IsDisposed)) {
                    using (费别人员维护编辑 frm = new 费别人员维护编辑()) {
                        frm.Id = this.Id;
                        if (frm.ShowDialog() == DialogResult.OK) {
                            selectValid();
                        }
                    }
                } else {
                    特殊费别审批管控编辑.Close();
                }
            }
            
        }

        private void btn_refresh_Click(object sender, EventArgs e) {
            selectValid();
        }
        private void selectValid() {
            string sql = @"select 管控ID,工号,研究者姓名,费别,项目名称 from 费别人员维护";
            dt = Adodb.QueryForTable(sql);
            dgv.DataSource = dt;
            dgv.ClearSelection();
        }

        private void btn_delete_Click(object sender, EventArgs e) {
            DataGridViewSelectedRowCollection selectedRows = dgv.SelectedRows;//选中行
            if (selectedRows == null || selectedRows.Count == 0) {
                MessageBox.Show("请选中一条维护信息");
                return;
            }
            data.id= Convert.ToInt64(selectedRows[0].Cells["管控ID"].Value);
            MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
            if (MessageBox.Show("确定要删除吗?", "删除确认", messButton) == DialogResult.OK) {
                 Adodb.Delete(data);
                MessageBox.Show("删除成功");
                selectValid();
            } else {
                return;
            }
        }

        private void btn_exit_Click(object sender, EventArgs e) {
            this.Close();
        }

        private void btn_find_Click(object sender, EventArgs e) {
            List<Object> parm = new List<object>();
            StringBuilder sql = new StringBuilder(@"select 管控ID,工号,研究者姓名,费别,项目名称 from 费别人员维护 where 1=1");
            sql.Append(" and 工号 LIKE ?");
            parm.Add(txt_no.Text + "%");
            dt = Adodb.QueryForTable(sql.ToString(), parm.ToArray());
            dgv.DataSource = dt;
        }
    }
}
